/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import model.CalcadosFiltradosMODEL;
import model.FuncionarioLogadoMODEL;
import org.postgresql.util.PSQLException;
import utilitarios.Data;

/**
 *
 * @author Welisson
 */
public class CalcadosFiltradosDAO extends GenericDAO{
    private static final String INSERT = "INSERT INTO experimentados(" +
"            fun_id, cal_id, exp_cat, exp_cor, exp_de, exp_ate, exp_data)" +
"    VALUES (?, ?, ?, ?, ?, ?, ?);" ;
    
    public boolean insert(List<CalcadosFiltradosMODEL> calcados) throws SQLException{
        
        PreparedStatement ps = conn.prepareStatement(INSERT, PreparedStatement.RETURN_GENERATED_KEYS);
        conn.setAutoCommit(false);
        
        try{
            
            for(CalcadosFiltradosMODEL calc : calcados){
                
                ps.setInt(1, new FuncionarioLogadoMODEL().getId());
                ps.setInt(2, calc.getCalcado());
                ps.setString(3, calc.getCategoria());
                ps.setString(4, calc.getCor());
                ps.setInt(5, calc.getDe());
                ps.setInt(6, calc.getAte());
                ps.setDate(7, new java.sql.Date(Data.dataDeHoje().getTime()));
                ps.execute();
            
                conn.commit();
                
            }
            
            
        }catch(PSQLException ex){
            ex.printStackTrace(System.out);
            conn.rollback();
            return false;
        }
        
        conn.setAutoCommit(true);
        ps.close();
        conn.close();
        return true;
        
    }
}
